package com.example.administrator.yanfoxconn.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TableRow;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.adapter.EmpListAdapter;
import com.example.administrator.yanfoxconn.adapter.IntelligenceGoodsListAdapter;
import com.example.administrator.yanfoxconn.bean.EmpFile;
import com.example.administrator.yanfoxconn.bean.GoodsMessage;
import com.example.administrator.yanfoxconn.constant.Constants;
import com.example.administrator.yanfoxconn.constant.FoxContext;
import com.example.administrator.yanfoxconn.utils.BaseActivity;
import com.example.administrator.yanfoxconn.utils.DateTimePickDialogUtil;
import com.example.administrator.yanfoxconn.utils.HttpUtils;
import com.example.administrator.yanfoxconn.utils.ToastUtils;
import com.example.administrator.yanfoxconn.widget.MyListView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import butterknife.BindView;
import butterknife.ButterKnife;
import taobe.tec.jcc.JChineseConvertor;

/**
 * 智慧型物品放行
 * Created by wangqian on 2019/07/01.
 */

public class GoodsIntelligenceActivity extends BaseActivity implements View.OnClickListener{
    private final int MESSAGE_SET_TEXT = 1;//掃描成功賦值
    private final int MESSAGE_TOAST = 2;//掃描失敗彈出框
    private final int MESSAGE_NETMISTAKE = 4;//網絡錯誤
    private final int MESSAGE_UP = 3;//提交信息回復
    private final int MESSAGE_SHOW = 5;//顯示提醒
    private final int MESSAGE_CHOISE = 6;//選擇
    private final int MESSAGE_SET_OUT_TEXT = 7;//已查验

    private String initStartDateTime; // 初始化开始时间
    private Date selectTime = null;//所選時間
    private Date curDate = null;//當前時間
    private String curDates;//當前時間
    private SimpleDateFormat formatter;
    @BindView(R.id.btn_title_left)
    Button btnBack;//返回
    @BindView(R.id.tv_title)
    TextView tvTitle;//標題
    @BindView(R.id.tv_show)
    TextView tvShow;//提示信息
    @BindView(R.id.btn_title_right)
    Button btnUp;//提交

    @BindView(R.id.tv_eff_num)
    TextView tvEffNum;//放行单号
    @BindView(R.id.tv_time)
    TextView tvTime;//有效日期
    @BindView(R.id.tv_out_to)
    TextView tvOutTo;//流出地點
    @BindView(R.id.tv_end_emp)
    TextView tvEndEmp;//接收單位
    @BindView(R.id.tv_cir_mode)
    TextView tvCirMode;//流通方式
    @BindView(R.id.lv_goods)
    MyListView lvGoods;//物品列表
    @BindView(R.id.tv_code)
    TextView tvCode;//攜帶人工號
    @BindView(R.id.tv_name)
    TextView tvName;//攜帶人姓名
    @BindView(R.id.tr_zian)
    TableRow trZiAn;
    @BindView(R.id.tr_zian_check)
    TableRow trZiAnCheck;
    @BindView(R.id.tv_zian_code)
    TextView tvZianCode;//資安人工號
    @BindView(R.id.tv_zian_guard)
    TextView tvZianName;//資安人姓名
    @BindView(R.id.tv_check_date)
    TextView tvCheckDate;//資安查驗時間

    @BindView(R.id.et_duty_code2)
    EditText etDutyCode2;//出二線当值警卫工號
    @BindView(R.id.et_duty_guard2)
    EditText etDutyGuard2;//出二線当值警卫姓名
    @BindView(R.id.tv_duty_code2)
    TextView tvDutyCode2;//出二線当值警卫工號
    @BindView(R.id.tv_duty_guard2)
    TextView tvDutyGuard2;//出二線当值警卫姓名
    @BindView(R.id.tv_release_date2)
    TextView tvReleaseDate2;//出二線放行時間
    @BindView(R.id.et_release_gate2)
    EditText etRelGate2;//出二線放行門崗
    @BindView(R.id.tv_release_gate2)
    TextView tvRelGate2;//出二線放行門崗
    @BindView(R.id.tr_list_gate2)
    TableRow trListGate2;//出二線
    @BindView(R.id.lv_gate2)
    MyListView lvGate2;//出二線放行門崗列表
    @BindView(R.id.tr_duty)
    TableRow trDuty;
    @BindView(R.id.tr_duty_date)
    TableRow trDutyDate;
    @BindView(R.id.tr_duty_gate)
    TableRow trDutyGate;
    @BindView(R.id.tv_duty_code)
    TextView tvDutyCode;//当值警卫工號
    @BindView(R.id.tv_duty_guard)
    TextView tvDutyGuard;//当值警卫姓名
    @BindView(R.id.tv_release_date)
    TextView tvReleaseDate;//放行時間
    @BindView(R.id.et_release_gate)
    EditText etRelGate;//放行門崗
    @BindView(R.id.tv_release_gate)
    TextView tvRelGate;//放行門崗
    @BindView(R.id.tr_list_gate)
    TableRow trListGate;
    @BindView(R.id.lv_gate)
    MyListView lvGate;//放行門崗列表


    @BindView(R.id.tr_in_duty)
    TableRow trInDuty;
    @BindView(R.id.tr_in_date)
    TableRow trInDate;
    @BindView(R.id.tr_in_gate)
    TableRow trInGate;
    @BindView(R.id.tv_in_duty_code)
    TextView tvInDutyCode;//入廠警卫工號
    @BindView(R.id.tv_in_duty_guard)
    TextView tvInDutyGuard;//入廠警卫姓名
    @BindView(R.id.tv_in_date)
    TextView tvInDate;//入廠時間
    @BindView(R.id.et_in_gate)
    EditText etInlGate;//入廠門崗
    @BindView(R.id.tv_in_gate)
    TextView tvInGate;//入廠門崗
    @BindView(R.id.tr_list_in_gate)
    TableRow trListInGate;
    @BindView(R.id.lv_in_gate)
    MyListView lvInGate;//入廠門崗列表
    @BindView(R.id.tr_in_duty2)
    TableRow trInDuty2;
    @BindView(R.id.tr_in_date2)
    TableRow trInDate2;
    @BindView(R.id.tr_in_gate2)
    TableRow trInGate2;
    @BindView(R.id.tv_in_duty2_code)
    TextView tvInDutyCode2;//入廠二線警卫工號
    @BindView(R.id.tv_in_duty2_guard)
    TextView tvInDutyGuard2;//入廠二線警卫姓名
    @BindView(R.id.tv_in_date2)
    TextView tvInDate2;//入廠二線時間
    @BindView(R.id.et_in_gate2)
    EditText etInlGate2;//入廠二線門崗
    @BindView(R.id.tv_in_gate2)
    TextView tvInGate2;//入廠二線門崗
    @BindView(R.id.tr_list_in_gate2)
    TableRow trListInGate2;
    @BindView(R.id.lv_in_gate2)
    MyListView lvInGate2;//入廠二線門崗列表

    private String code;//工號或車牌
    private String id="";//放行單號后4位
    private String url;//地址
    private String result;//网络获取结果
    private List<GoodsMessage> goodsMessage;//物品信息
    private List<GoodsMessage> goodsList;//物品列表
    private IntelligenceGoodsListAdapter goodsListAdapter;//物品列表适配器

    private List<String> teamList,team2List,teamInList;
    private EmpListAdapter mAdapter,mAdapter2,inMAdaptr,inMAdaptr2;
    private List<EmpFile> empFileList;
    private AlertDialog alertDialog1; //信息框
    private String[] dandan;//有多個單號時的單號
    private String flagInOut="OUT";//進IN或出OUT
    private String outStatue="";//无未操作，1资安已查验，2门岗已放行
    private String outFlag ="";//流通方式 in,out,out1

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_intelligence);
        ButterKnife.bind(this);

        code = getIntent().getStringExtra("code");
//        id = getIntent().getStringExtra("id");

        tvTitle.setText("智慧物品放行");
        btnBack.setOnClickListener(this);
        btnUp.setText("提交");
        btnUp.setVisibility(View.VISIBLE);
        btnUp.setOnClickListener(this);
        etRelGate.setTag("0");//用於判斷是否選擇門崗0;為未選擇,其他為選擇
        etInlGate.setTag("0");//用於判斷是否選擇門崗0;為未選擇,其他為選擇
        etRelGate2.setTag("0");//用於判斷是否選擇門崗0;為未選擇,其他為選擇
        etInlGate2.setTag("0");//用於判斷是否選擇門崗0;為未選擇,其他為選擇
        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        SimpleDateFormat formatterUse = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        curDate = new Date(System.currentTimeMillis());
        //获取当前时间
        initStartDateTime = formatterUse.format(curDate);
        tvCheckDate.setText(formatter.format(curDate));
        tvReleaseDate.setText(formatter.format(curDate));
        tvReleaseDate2.setText(formatter.format(curDate));
        tvInDate2.setText(formatter.format(curDate));
        tvInDate.setText(formatter.format(curDate));
        curDates = formatter.format(curDate);
        getMessage(code,id);

        //搜索关键字
        etRelGate.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                trListGate.setVisibility(View.VISIBLE);
                String a = etRelGate.getText().toString().toUpperCase();
                //调用适配器里面的搜索方法
                mAdapter.SearchCity(a);
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }

        }); //搜索关键字
        etRelGate2.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                trListGate2.setVisibility(View.VISIBLE);
                String a = etRelGate2.getText().toString().toUpperCase();
                //调用适配器里面的搜索方法
                mAdapter2.SearchCity(a);
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }

        });
        //搜索关键字
        etInlGate.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                trListInGate.setVisibility(View.VISIBLE);
                String a = etInlGate.getText().toString().toUpperCase();
                //调用适配器里面的搜索方法
                inMAdaptr.SearchCity(a);
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }

        });//搜索关键字
        etInlGate2.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                trListInGate2.setVisibility(View.VISIBLE);
                String a = etInlGate2.getText().toString().toUpperCase();
                //调用适配器里面的搜索方法
                inMAdaptr2.SearchCity(a);
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }

        });


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_title_left:
                finish();
                break;
            case R.id.btn_title_right:

                check();
                break;
        }
    }
    //提交前檢查
    private void check(){
        if(FoxContext.getInstance().getLoginId().equals("")){
            ToastUtils.showLong(GoodsIntelligenceActivity.this,"登錄超時,請退出重新登登錄!");
            return;
        }
        try {
            selectTime = formatter.parse(tvCheckDate.getText().toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (FoxContext.getInstance().getDep().equals("資安")){//資安權限
            if (outFlag.equals("in")){
                ToastUtils.showShort(GoodsIntelligenceActivity.this,"厂区内流通，资安无需操作！");
            }else{
                if (outStatue.equals("")) {
                    upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvZianCode.getText().toString(), tvZianName.getText().toString(), "zian", "", tvCheckDate.getText().toString(),outFlag);
                }else if (outStatue.equals("0")){
                    upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvZianCode.getText().toString(), tvZianName.getText().toString(), "zian", "", tvCheckDate.getText().toString(),outFlag);
                }else {
                    ToastUtils.showShort(GoodsIntelligenceActivity.this,"资安已查验，请勿重复操作！");
                }
            }
        }else{//安保部權限
//            if (selectTime.getTime()-curDate.getTime()>0){
//                ToastUtils.showShort(GoodsIntelligenceActivity.this,"放行時間不能超過當前時間");
//                return;
//            }
            if (outStatue.equals("")) {//ZH_GOOD無數據
                if (outFlag.equals("in")){//廠區內流通，二線出必有
//                    if (!etDutyCode2.getText().toString().equals("")){//判斷二線出工號是否有數據
                        //二線出有數據
                        if (etRelGate2.getTag().equals("0")) {
                            //二線出數據不完整，需補充
                            ToastUtils.showShort(GoodsIntelligenceActivity.this, "請填寫或選擇完整二線放行門崗信息!");
                            return;
                        }else{if(!etDutyCode2.getText().toString().equals(FoxContext.getInstance().getLoginId())||!etDutyGuard2.getText().toString().equals(FoxContext.getInstance().getName())){
                            //二線出數據不符合
                            ToastUtils.showShort(GoodsIntelligenceActivity.this, "請填寫正確二線放行門崗警衛信息!需與登錄帳號一致！");
                            return;
                        }else{
                            //二線出數據完整，提交
                            upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), etDutyCode2.getText().toString(), etDutyGuard2.getText().toString(), "OUT2", change(etRelGate2.getText().toString()), tvReleaseDate2.getText().toString(),outFlag);
                        }}
//                    }else{
//                        //二線出無數據，則不可提交
//                        ToastUtils.showShort(GoodsIntelligenceActivity.this, "二線門崗信息未填寫!");
//                        return;
//                    }
               }else if(!etDutyCode2.getText().toString().equals("")){//判斷out,out1下 二線出工號是否有數據
                    //二線出有數據
                    if (etRelGate2.getTag().equals("0")||etDutyGuard2.getText().toString().equals("")) {
                        //二線出數據不完整，需補充
                        ToastUtils.showShort(GoodsIntelligenceActivity.this, "請填寫或選擇完整二線放行門崗信息!");
                        return;
                    }else{
                        if(!etDutyCode2.getText().toString().equals(FoxContext.getInstance().getLoginId())||!etDutyGuard2.getText().toString().equals(FoxContext.getInstance().getName())){
                            //二線出數據不符合
                            ToastUtils.showShort(GoodsIntelligenceActivity.this, "請填寫正確二線放行門崗警衛信息!需與登錄帳號一致！");
                            return;
                        }else{
                            //二線出數據完整，提交
                            upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), etDutyCode2.getText().toString(), etDutyGuard2.getText().toString(), "OUT2", change(etRelGate2.getText().toString()), tvReleaseDate2.getText().toString(), outFlag);
                        }
                    }
                }else{
                    ToastUtils.showShort(GoodsIntelligenceActivity.this,"资安未查验，不可操作！");
                }
            }else if (outStatue.equals("0")){//二線已出
                if (outFlag.equals("in")){//in廠區內，二線已出，此時需判斷二線入
                    if (etInlGate2.getTag().equals("0")) {
                        ToastUtils.showShort(GoodsIntelligenceActivity.this, "請選擇二線入廠門崗!");
                        return;
                    }
                    //in廠區內，二線入
                    upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvInDutyCode2.getText().toString(), tvInDutyGuard2.getText().toString(), "IN2", change(etInlGate2.getText().toString()), tvInDate2.getText().toString(),outFlag);
                }else{//out,out1二線已出，此時需判斷資安
                    ToastUtils.showShort(GoodsIntelligenceActivity.this,"资安未查验，不可操作！");
                }
            }else if (outStatue.equals("1")) {//資安已查驗
                if (outFlag.equals("in")){//in廠區內，不可能出現資安
                    ToastUtils.showShort(GoodsIntelligenceActivity.this,"此單狀態異常，請聯繫管理員！");
                }else {//out,out1資安已查驗，此時需判斷一線出
                    if (etRelGate.getTag().equals("0")) {
                        ToastUtils.showShort(GoodsIntelligenceActivity.this, "請選擇一線放行門崗!");
                        return;
                    }
                    //out,out1資安已查驗，一線出
                    upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvDutyCode.getText().toString(), tvDutyGuard.getText().toString(), "OUT1", change(etRelGate.getText().toString()), tvReleaseDate.getText().toString(),outFlag);
                }
            }else if (outStatue.equals("2")&&outFlag.equals("out")){//跨廠區，一線已出
                if (etInlGate.getTag().equals("0")) {//判斷一線入
                    ToastUtils.showShort(GoodsIntelligenceActivity.this, "請選擇一線入廠門崗!");
                    return;
                }
                //out一線已出，一線入
                upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvInDutyCode.getText().toString(), tvInDutyGuard.getText().toString(), "IN1", change(etInlGate.getText().toString()), tvInDate.getText().toString(),outFlag);
            }else if(outStatue.equals("3")&&outFlag.equals("out")){//跨廠區，一線已入
                if (etInlGate2.getTag().equals("0")) {//判斷二線入
                    ToastUtils.showShort(GoodsIntelligenceActivity.this, "請選擇入廠二線門崗!");
                    return;
                }
                //out一線已入，二線入
                upMsessage(tvEffNum.getText().toString(), goodsMessage.get(0).getEMPNO(), goodsMessage.get(0).getEMPNAME(), tvInDutyCode2.getText().toString(), tvInDutyGuard2.getText().toString(), "IN2", change(etInlGate2.getText().toString()), tvInDate2.getText().toString(),outFlag);
            }else{
                ToastUtils.showShort(GoodsIntelligenceActivity.this,"此單已結束，不可操作！");
            }
        }
    }

    private void getMessage(String code, String id) {
        showDialog();
        try {
            String code1 =  URLEncoder.encode(URLEncoder.encode(code.toString(), "UTF-8"), "UTF-8");
            url = Constants.HTTP_INTELLIGENCE_GOODS_SERVLET + "?flag=CC" + "&code=" + code1 + "&id=" + id;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Log.e("-----------", "url-----" + url);
        new Thread() {
            @Override
            public void run() {
                result = HttpUtils.queryStringForPost(url);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        Log.e("--fff---------", "result==" + result);
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        goodsMessage = new ArrayList<GoodsMessage>();
                        for (JsonElement type : array) {
                            GoodsMessage humi = gson.fromJson(type, GoodsMessage.class);
                            goodsMessage.add(humi);
                        }

                        JsonObject jsonObject1 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array1 = jsonObject1.get("file").getAsJsonArray();
                        empFileList = new ArrayList<EmpFile>();
                        for (JsonElement type1 : array1) {
                            EmpFile humi1 = gson.fromJson(type1, EmpFile.class);
                            empFileList.add(humi1);
                        }

                        JsonObject jsonObject2 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array2 = jsonObject2.get("file2").getAsJsonArray();
                        goodsList = new ArrayList<GoodsMessage>();
                        for (JsonElement type2 : array2) {
                            GoodsMessage humi2 = gson.fromJson(type2, GoodsMessage.class);
                            goodsList.add(humi2);
                        }

                        Message message = new Message();
                        message.what = MESSAGE_SET_TEXT;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }else if (errCode.equals("202")) {
                        Log.e("--fff---------", "result==" + result);
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        goodsMessage = new ArrayList<GoodsMessage>();
                        for (JsonElement type : array) {
                            GoodsMessage humi = gson.fromJson(type, GoodsMessage.class);
                            goodsMessage.add(humi);
                        }

                        JsonObject jsonObject1 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array1 = jsonObject1.get("file").getAsJsonArray();
                        empFileList = new ArrayList<EmpFile>();
                        for (JsonElement type1 : array1) {
                            EmpFile humi1 = gson.fromJson(type1, EmpFile.class);
                            empFileList.add(humi1);
                        }

                        JsonObject jsonObject2 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array2 = jsonObject2.get("file2").getAsJsonArray();
                        goodsList = new ArrayList<GoodsMessage>();
                        for (JsonElement type2 : array2) {
                            GoodsMessage humi2 = gson.fromJson(type2, GoodsMessage.class);
                            goodsList.add(humi2);
                        }

                        Message message = new Message();
                        message.what = MESSAGE_SET_OUT_TEXT;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }else if (errCode.equals("300")) {
                        Log.e("--fff---------", "result==" + result);
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        goodsMessage = new ArrayList<GoodsMessage>();
                        for (JsonElement type : array) {
                            GoodsMessage humi = gson.fromJson(type, GoodsMessage.class);
                            goodsMessage.add(humi);
                        }

                        JsonObject jsonObject1 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array1 = jsonObject1.get("file").getAsJsonArray();
                        empFileList = new ArrayList<EmpFile>();
                        for (JsonElement type1 : array1) {
                            EmpFile humi1 = gson.fromJson(type1, EmpFile.class);
                            empFileList.add(humi1);
                        }

                        JsonObject jsonObject2 = new JsonParser().parse(String.valueOf(array.get(0))).getAsJsonObject();
                        JsonArray array2 = jsonObject2.get("file2").getAsJsonArray();
                        goodsList = new ArrayList<GoodsMessage>();
                        for (JsonElement type2 : array2) {
                            GoodsMessage humi2 = gson.fromJson(type2, GoodsMessage.class);
                            goodsList.add(humi2);
                        }

                        Message message = new Message();
                        message.what = MESSAGE_SHOW;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }else if (errCode.equals("500")) {
                        String ss = jsonObject.get("data").toString();
                        JSONArray array = null;
                        try {
                            array = new JSONArray(ss);
                            dandan=new String[array.length()];
                            for (int i=0;i<array.length();i++) {
                                JSONObject dan = array.getJSONObject(i);// 遍历 jsonarray 数组，把每一个对象转成 json 对象
                                dandan[i]=dan.getString("DOCUMENT_NO");
                                Log.e("-------dandan---------",dandan[i]);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        Message message = new Message();
                        message.what = MESSAGE_CHOISE;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }else{
                        Log.e("-----------", "result==" + result);
                        Message message = new Message();
                        message.what = MESSAGE_TOAST;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    }
                }else{
                    Message message = new Message();
                    message.what = MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                }
            } }.start();
    }

    //彈出選擇單號框
    public void showList(String[] dan){
        final String[] items = dan;
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
        alertBuilder.setTitle("請選擇單號");
        alertBuilder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                getMessage(code,items[i]);
                alertDialog1.dismiss();
            }
        });
        alertDialog1 = alertBuilder.create();
        alertDialog1.show();
        alertDialog1.setCanceledOnTouchOutside(false);
    }

    //提交数据
    private void upMsessage(String id,String code, String name,String cCode,String cName,String flagInOut,String mengang,String creat_date,String outFlag){
        showDialog();
        try {
            String name1 =  URLEncoder.encode(URLEncoder.encode(name.toString(), "UTF-8"), "UTF-8");
            String cName1 =  URLEncoder.encode(URLEncoder.encode(cName.toString(), "UTF-8"), "UTF-8");
            String flagInOut1 =  URLEncoder.encode(URLEncoder.encode(flagInOut.toString(), "UTF-8"), "UTF-8");
            String creat_date1 =  URLEncoder.encode(URLEncoder.encode(creat_date.toString(), "UTF-8"), "UTF-8");
            String mengang1 =  URLEncoder.encode(URLEncoder.encode(mengang.toString(), "UTF-8"), "UTF-8");
            url = Constants.HTTP_INTELLIGENCE_GOODS_SERVLET + "?flag=TT" + "&code=" + code + "&id=" + id+ "&name=" + name1+ "&cCode=" + cCode+ "&cName=" + cName1 + "&mengang=" + mengang1 + "&flagInOut=" + flagInOut1 +"&creat_date=" + creat_date1 +"&outFlag=" + outFlag;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Log.e("-----------", "url-----" + url);
        new Thread() {
            @Override
            public void run() {
                result = HttpUtils.queryStringForPost(url);
                dismissDialog();

                if (result != null) {
                    Log.e("---------", "result==fff===" + result);

                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        Log.e("--fff---------", "result==" + result);

                        Message message = new Message();
                        message.what = MESSAGE_TOAST;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    } else{
                        Log.e("-----------", "result==" + result);
                        Message message = new Message();
                        message.what = MESSAGE_UP;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    }
                }else{
                    Message message = new Message();
                    message.what = MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                }
            } }.start();
    }

    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case MESSAGE_TOAST://Toast彈出
                    aboutAlert(msg.obj.toString(),MESSAGE_TOAST);

//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
//                    finish();
                    break;
                case MESSAGE_NETMISTAKE://Toast彈出
                    ToastUtils.showLong(GoodsIntelligenceActivity.this,R.string.net_mistake);
                    break;
                case MESSAGE_SET_TEXT://text賦值
                    setText();
//                    aboutAlert(msg.obj.toString(),MESSAGE_SET_TEXT);
                    break;
                case MESSAGE_SET_OUT_TEXT:
                    setOutText();
                    break;
                case MESSAGE_CHOISE://text賦值
                    showList(dandan);
                    break;
                case MESSAGE_UP://提交響應
                    worningAlert(msg.obj.toString(),MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
                case MESSAGE_SHOW://顯示提醒
                    setText();
                    tvShow.setVisibility(View.VISIBLE);
                    tvShow.setText(msg.obj.toString());
                    break;
            }
            super.handleMessage(msg);
        }
    };

    //第一次zh_good沒信息時
    private void setText() {
        outFlag =goodsMessage.get(0).getOUT_FLAG();
        if (FoxContext.getInstance().getDep().equals("資安")){
            //默認 二線出可不填，資安查驗有內容，一線出無內容
            tvZianCode.setText(FoxContext.getInstance().getLoginId());
            tvZianName.setText(FoxContext.getInstance().getName());
            tvReleaseDate.setText("");
        }else{
            Log.e("-------","setText2");
            if (outFlag.equals("in")){
                tvDutyCode2.setText(FoxContext.getInstance().getLoginId());
                tvDutyGuard2.setText(FoxContext.getInstance().getName());
                tvDutyCode2.setVisibility(View.VISIBLE);
                tvDutyGuard2.setVisibility(View.VISIBLE);
                etDutyCode2.setVisibility(View.GONE);
                etDutyGuard2.setVisibility(View.GONE);
                trInDate2.setVisibility(View.GONE);
                trInDuty2.setVisibility(View.GONE);
                trInGate2.setVisibility(View.GONE);
                trDuty.setVisibility(View.GONE);
                trDutyDate.setVisibility(View.GONE);
                trDutyGate.setVisibility(View.GONE);
            }else {
                //先默認 二線出不填一線出默認有內容 除非二線出工號有內容，再清空一線出內容
                tvCheckDate.setText("");//安保權限，資安查驗內容為空
                tvDutyCode.setText(FoxContext.getInstance().getLoginId());
                tvDutyGuard.setText(FoxContext.getInstance().getName());
                tvReleaseDate.setText(formatter.format(curDate));
                tvReleaseDate2.setText("");
                etDutyCode2.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        if (etDutyCode2.getText().toString().equals("")) {
                            tvDutyCode.setText(FoxContext.getInstance().getLoginId());
                            tvDutyGuard.setText(FoxContext.getInstance().getName());
                            tvReleaseDate.setText(formatter.format(curDate));
                            tvReleaseDate2.setText("");
                            Log.e("-------", "setText3");
                        } else {
                            tvReleaseDate2.setText(formatter.format(curDate));
                            tvDutyCode.setText("");
                            tvDutyGuard.setText("");
                            tvReleaseDate.setText("");
                            Log.e("-------", "setText4");
                        }
                    }
                });
                tvShow.setVisibility(View.VISIBLE);
                tvShow.setBackgroundResource(R.color.color_d73d19);
                tvShow.setText("请注意资安未查验贴封！");
            } }
        tvEffNum.setText(goodsMessage.get(0).getDOCUMENT_NO());
        tvTime.setText(goodsMessage.get(0).getOUT_STDATE()+" >>> "+goodsMessage.get(0).getOUT_ENDDATE());
        tvOutTo.setText(goodsMessage.get(0).getTAKETO_PLACE().split("@@@")[0].replaceAll("###","-"));
        tvEndEmp.setText(goodsMessage.get(0).getTAKETO_PLACE().split("@@@")[1].replaceAll("###","-"));
        tvCode.setText(goodsMessage.get(0).getEMPNO());
        tvName.setText(goodsMessage.get(0).getEMPNAME());
//        tvDutyGuard.setText(FoxContext.getInstance().getName());
        if(goodsMessage.get(0).getBRING_OUT().equals("ON")){
            if(goodsMessage.get(0).getOUT_FLAG().equals("in")){
                tvShow.setVisibility(View.GONE);
                trZiAn.setVisibility(View.GONE);
                trZiAnCheck.setVisibility(View.GONE);
                tvCirMode.setText("廠區內");
            }else if(goodsMessage.get(0).getOUT_FLAG().equals("out")){
                tvCirMode.setText("跨廠區");
            }else{
                tvCirMode.setText("廠區外");
            }
            tvOutTo.setText(goodsMessage.get(0).getTAKETO_PLACE().replaceAll("###"," ").replaceAll("@@@"," >>> "));
//            tvEffDate.setText(goodsMessage.get(0).getOUT_STDATE()+" >>> "+goodsMessage.get(0).getOUT_ENDDATE());
        }
//        else{
//            tvCirMode.setText("攜入");
//            tvOutTo.setText(goodsMessage.get(0).getTAKEIN_PLACE());
////            tvEffDate.setText(goodsMessage.get(0).getIN_STDATE()+" >>> "+goodsMessage.get(0).getIN_ENDDATE());
//        }

        goodsListAdapter = new IntelligenceGoodsListAdapter(GoodsIntelligenceActivity.this, goodsList);
        lvGoods.setAdapter(goodsListAdapter);

        teamList = new ArrayList<>();
        for (int i = 0;i<empFileList.size();i++){
            teamList.add(change1(empFileList.get(i).getID()+","+empFileList.get(i).getAQ1()+"-"+empFileList.get(i).getAQ2()+"-"+empFileList.get(i).getAQ3()+"-"+empFileList.get(i).getAQ4()));
        }
        mAdapter = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvGate.setAdapter(mAdapter);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        mAdapter.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etRelGate.setText(tit.split(",")[1]);
                etRelGate.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                mAdapter.SearchCity("");
                trListGate.setVisibility(View.GONE);
            }
            @Override
            public void OnClicktv(String tit, String tv) {
            }
        });

        team2List = new ArrayList<>();
        for (int i = 0;i<empFileList.size();i++){
            team2List.add(change1(empFileList.get(i).getID()+","+empFileList.get(i).getAQ1()+"-"+empFileList.get(i).getAQ2()+"-"+empFileList.get(i).getAQ3()+"-"+empFileList.get(i).getAQ4()));
        }

        mAdapter2 = new EmpListAdapter(GoodsIntelligenceActivity.this,team2List);
        lvGate2.setAdapter(mAdapter2);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        mAdapter2.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etRelGate2.setText(tit.split(",")[1]);
                etRelGate2.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                mAdapter2.SearchCity("");
                trListGate2.setVisibility(View.GONE);
            }
            @Override
            public void OnClicktv(String tit, String tv) {
            }
        });
        inMAdaptr2 = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvInGate2.setAdapter(inMAdaptr2);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        inMAdaptr2.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etInlGate2.setText(tit.split(",")[1]);
                etInlGate2.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                inMAdaptr2.SearchCity("");
                trListInGate2.setVisibility(View.GONE);
            }

            @Override
            public void OnClicktv(String tit, String tv) {

            }
        });
    }

    private void setOutText() {
        outStatue=goodsMessage.get(0).getOUT_STATUE();
        outFlag =goodsMessage.get(0).getOUT_FLAG();
        if (outStatue.equals("4")){
            tvDutyCode2.setText(goodsMessage.get(0).getOUT2_DUTY_CODE());
            tvDutyGuard2.setText(goodsMessage.get(0).getOUT2_DUTY_NAME());
            tvDutyCode2.setVisibility(View.VISIBLE);
            tvDutyGuard2.setVisibility(View.VISIBLE);
            tvRelGate2.setText(goodsMessage.get(0).getOUT2_MENGANG());
            tvRelGate2.setVisibility(View.VISIBLE);
            etRelGate2.setVisibility(View.GONE);
            etDutyGuard2.setVisibility(View.GONE);
            etDutyCode2.setVisibility(View.GONE);
            trInGate2.setVisibility(View.VISIBLE);
            trInDuty2.setVisibility(View.VISIBLE);
            trInDate2.setVisibility(View.VISIBLE);
            tvReleaseDate2.setText(goodsMessage.get(0).getOUT2_DUTY_DATE());
            tvInDutyCode2.setText(goodsMessage.get(0).getIN2_DUTY_CODE());
            tvInDutyGuard2.setText(goodsMessage.get(0).getIN2_DUTY_NAME());
            tvInGate2.setText(goodsMessage.get(0).getIN2_MENGANG());
            tvInGate2.setVisibility(View.VISIBLE);
            etInlGate2.setVisibility(View.GONE);
            tvInDate2.setText(goodsMessage.get(0).getIN2_DUTY_DATE());
            if (outFlag.equals("out")){
                tvZianCode.setText(goodsMessage.get(0).getZIAN_CODE());
                tvZianName.setText(goodsMessage.get(0).getZIAN_NAME());
                tvCheckDate.setText(goodsMessage.get(0).getZIAN_CREATE_DATE());
                tvDutyCode.setText(goodsMessage.get(0).getOUT_DUTY_CODE());
                tvDutyGuard.setText(goodsMessage.get(0).getOUT_DUTY_NAME());
                tvRelGate.setText(goodsMessage.get(0).getOUT_MENGANG());
                tvRelGate.setVisibility(View.VISIBLE);
                etRelGate.setVisibility(View.GONE);
                tvReleaseDate.setText(goodsMessage.get(0).getOUT_DUTY_DATE());
                trInDate.setVisibility(View.VISIBLE);
                trInDuty.setVisibility(View.VISIBLE);
                trInGate.setVisibility(View.VISIBLE);
                tvInDutyCode.setText(goodsMessage.get(0).getIN_DUTY_CODE());
                tvInDutyGuard.setText(goodsMessage.get(0).getIN_DUTY_NAME());
                tvInGate.setText(goodsMessage.get(0).getIN_MENGANG());
                tvInGate.setVisibility(View.VISIBLE);
                etInlGate.setVisibility(View.GONE);
                tvInDate.setText(goodsMessage.get(0).getIN2_DUTY_DATE());
            }else if (outFlag.equals("in")){
                trDuty.setVisibility(View.GONE);
                trDutyGate.setVisibility(View.GONE);
                trDutyDate.setVisibility(View.GONE);

            }
            tvShow.setVisibility(View.VISIBLE);
            tvShow.setText("请注意此单已結束，请勿重复操作！");
        }else if (outStatue.equals("3")&&outFlag.equals("out")){
            tvDutyCode2.setText(goodsMessage.get(0).getOUT2_DUTY_CODE());
            tvDutyGuard2.setText(goodsMessage.get(0).getOUT2_DUTY_NAME());
            tvRelGate2.setText(goodsMessage.get(0).getOUT2_MENGANG());
            tvRelGate2.setVisibility(View.VISIBLE);
            etRelGate2.setVisibility(View.GONE);
            tvReleaseDate2.setText(goodsMessage.get(0).getOUT2_DUTY_DATE());
            tvZianCode.setText(goodsMessage.get(0).getZIAN_CODE());
            tvZianName.setText(goodsMessage.get(0).getZIAN_NAME());
            tvCheckDate.setText(goodsMessage.get(0).getZIAN_CREATE_DATE());
            tvDutyCode.setText(goodsMessage.get(0).getOUT_DUTY_CODE());
            tvDutyGuard.setText(goodsMessage.get(0).getOUT_DUTY_NAME());
            tvRelGate.setText(goodsMessage.get(0).getOUT_MENGANG());
            tvRelGate.setVisibility(View.VISIBLE);
            etRelGate.setVisibility(View.GONE);
            tvReleaseDate.setText(goodsMessage.get(0).getOUT_DUTY_DATE());
            tvInDutyCode.setText(goodsMessage.get(0).getIN_DUTY_CODE());
            tvInDutyGuard.setText(goodsMessage.get(0).getIN_DUTY_NAME());
            tvInGate.setText(goodsMessage.get(0).getIN_MENGANG());
            tvInGate.setVisibility(View.VISIBLE);
            etInlGate.setVisibility(View.GONE);
            tvInDate.setText(goodsMessage.get(0).getIN_DUTY_DATE());
            trInDate.setVisibility(View.VISIBLE);
            trInDuty.setVisibility(View.VISIBLE);
            trInGate.setVisibility(View.VISIBLE);
            tvInDutyCode2.setText(FoxContext.getInstance().getLoginId());
            tvInDutyGuard2.setText(FoxContext.getInstance().getName());
            trInDate2.setVisibility(View.VISIBLE);
            trInDuty2.setVisibility(View.VISIBLE);
            trInGate2.setVisibility(View.VISIBLE);
            tvShow.setText("请注意此单已放行，現進行二線門崗入廠操作！");
        }else if (outStatue.equals("2")){
            tvDutyCode2.setText(goodsMessage.get(0).getOUT2_DUTY_CODE());
            tvDutyGuard2.setText(goodsMessage.get(0).getOUT2_DUTY_NAME());
            tvDutyCode2.setVisibility(View.VISIBLE);
            tvDutyGuard2.setVisibility(View.VISIBLE);
            etDutyCode2.setVisibility(View.GONE);
            etDutyGuard2.setVisibility(View.GONE);
            tvRelGate2.setText(goodsMessage.get(0).getOUT2_MENGANG());
            tvRelGate2.setVisibility(View.VISIBLE);
            etRelGate2.setVisibility(View.GONE);
            tvReleaseDate2.setText(goodsMessage.get(0).getOUT2_DUTY_DATE());
            tvZianCode.setText(goodsMessage.get(0).getZIAN_CODE());
            tvZianName.setText(goodsMessage.get(0).getZIAN_NAME());
            tvCheckDate.setText(goodsMessage.get(0).getZIAN_CREATE_DATE());
            tvDutyCode.setText(goodsMessage.get(0).getOUT_DUTY_CODE());
            tvDutyGuard.setText(goodsMessage.get(0).getOUT_DUTY_NAME());
            tvRelGate.setText(goodsMessage.get(0).getOUT_MENGANG());
            tvRelGate.setVisibility(View.VISIBLE);
            etRelGate.setVisibility(View.GONE);
            tvReleaseDate.setText(goodsMessage.get(0).getOUT_DUTY_DATE());
            if (outFlag.equals("out")){
                if(FoxContext.getInstance().getDep().equals("資安")){}else{
                    tvInDutyCode.setText(FoxContext.getInstance().getLoginId());
                    tvInDutyGuard.setText(FoxContext.getInstance().getName());
                }
                trInDate.setVisibility(View.VISIBLE);
                trInDuty.setVisibility(View.VISIBLE);
                trInGate.setVisibility(View.VISIBLE);
                tvShow.setVisibility(View.VISIBLE);
                tvShow.setText("请注意此单已放行，現進行一線門崗入廠操作！");

            }else{
                tvShow.setVisibility(View.VISIBLE);
                tvShow.setText("请注意此单已放行，请勿重复操作！");
            }
        }else if (outStatue.equals("1")){
            tvDutyCode2.setText(goodsMessage.get(0).getOUT2_DUTY_CODE());
            tvDutyGuard2.setText(goodsMessage.get(0).getOUT2_DUTY_NAME());
            tvDutyCode2.setVisibility(View.VISIBLE);
            tvDutyGuard2.setVisibility(View.VISIBLE);
            etDutyCode2.setVisibility(View.GONE);
            etDutyGuard2.setVisibility(View.GONE);
            tvRelGate2.setText(goodsMessage.get(0).getOUT2_MENGANG());
            tvRelGate2.setVisibility(View.VISIBLE);
            etRelGate2.setVisibility(View.GONE);
            tvReleaseDate2.setText(goodsMessage.get(0).getOUT2_DUTY_DATE());
            tvZianCode.setText(goodsMessage.get(0).getZIAN_CODE());
            tvZianName.setText(goodsMessage.get(0).getZIAN_NAME());
            tvCheckDate.setText(goodsMessage.get(0).getZIAN_CREATE_DATE());
            //默認一線門崗出顯示
            tvShow.setVisibility(View.VISIBLE);
            tvShow.setText("请注意资安已查验，現進行一線門崗出廠操作！");
             if(FoxContext.getInstance().getDep().equals("資安")){}else {
                tvDutyCode.setText(FoxContext.getInstance().getLoginId());
                tvDutyGuard.setText(FoxContext.getInstance().getName());
            }
        }else if (outStatue.equals("0")){
            tvDutyCode2.setText(goodsMessage.get(0).getOUT2_DUTY_CODE());
            tvDutyGuard2.setText(goodsMessage.get(0).getOUT2_DUTY_NAME());
            tvDutyCode2.setVisibility(View.VISIBLE);
            tvDutyGuard2.setVisibility(View.VISIBLE);
            tvRelGate2.setText(goodsMessage.get(0).getOUT2_MENGANG());
            tvRelGate2.setVisibility(View.VISIBLE);
            etRelGate2.setVisibility(View.GONE);
            tvReleaseDate2.setText(goodsMessage.get(0).getOUT2_DUTY_DATE());
            etDutyCode2.setVisibility(View.GONE);
            etDutyGuard2.setVisibility(View.GONE);
            tvInDutyCode.setText(FoxContext.getInstance().getLoginId());
            tvInDutyGuard.setText(FoxContext.getInstance().getName());
            if (outFlag.equals("in")){//廠區內，二線已出，待二線入
                tvInDutyCode2.setText(FoxContext.getInstance().getLoginId());
                tvInDutyGuard2.setText(FoxContext.getInstance().getName());
                trInDate2.setVisibility(View.VISIBLE);
                trInDuty2.setVisibility(View.VISIBLE);
                trInGate2.setVisibility(View.VISIBLE);
                trZiAn.setVisibility(View.GONE);
                trZiAnCheck.setVisibility(View.GONE);
                trDuty.setVisibility(View.GONE);
                trDutyDate.setVisibility(View.GONE);
                trDutyGate.setVisibility(View.GONE);
            }else if(FoxContext.getInstance().getDep().equals("資安")){
            tvZianCode.setText(FoxContext.getInstance().getLoginId());
            tvZianName.setText(FoxContext.getInstance().getName());
            }
            //默認資安查驗和一線門崗出顯示
        }
//        else{
//            tvZianCode.setText(goodsMessage.get(0).getZIAN_CODE());
//            tvZianName.setText(goodsMessage.get(0).getZIAN_NAME());
//            tvCheckDate.setText(goodsMessage.get(0).getZIAN_CREATE_DATE());
//            tvShow.setVisibility(View.VISIBLE);
//            tvShow.setText("资安已查验！");
//            tvDutyCode.setText(FoxContext.getInstance().getLoginId());
//            tvDutyGuard.setText(FoxContext.getInstance().getName());
//        }
        tvEffNum.setText(goodsMessage.get(0).getDOCUMENT_NO());
        tvTime.setText(goodsMessage.get(0).getOUT_STDATE()+" >>> "+goodsMessage.get(0).getOUT_ENDDATE());
        tvOutTo.setText(goodsMessage.get(0).getTAKETO_PLACE().split("@@@")[0].replaceAll("###","-"));
        tvEndEmp.setText(goodsMessage.get(0).getTAKETO_PLACE().split("@@@")[1].replaceAll("###","-"));
        tvCode.setText(goodsMessage.get(0).getEMPNO());
        tvName.setText(goodsMessage.get(0).getEMPNAME());
        if(goodsMessage.get(0).getBRING_OUT().equals("ON")){
            if(goodsMessage.get(0).getOUT_FLAG().equals("in")){
                tvCirMode.setText("廠區內");
                trZiAn.setVisibility(View.GONE);
                trZiAnCheck.setVisibility(View.GONE);
            }else if(goodsMessage.get(0).getOUT_FLAG().equals("out")){
                tvCirMode.setText("跨廠區");
            }else{
                tvCirMode.setText("廠區外");
            }
            tvOutTo.setText(goodsMessage.get(0).getTAKETO_PLACE().replaceAll("###"," ").replaceAll("@@@"," >>> "));
//            tvEffDate.setText(goodsMessage.get(0).getOUT_STDATE()+" >>> "+goodsMessage.get(0).getOUT_ENDDATE());
        }
//        else{
//            tvCirMode.setText("攜入");
//            tvOutTo.setText(goodsMessage.get(0).getTAKEIN_PLACE());
////            tvEffDate.setText(goodsMessage.get(0).getIN_STDATE()+" >>> "+goodsMessage.get(0).getIN_ENDDATE());
//        }

        goodsListAdapter = new IntelligenceGoodsListAdapter(GoodsIntelligenceActivity.this, goodsList);
        lvGoods.setAdapter(goodsListAdapter);

        teamList = new ArrayList<>();
        for (int i = 0;i<empFileList.size();i++){
            teamList.add(change1(empFileList.get(i).getID()+","+empFileList.get(i).getAQ1()+"-"+empFileList.get(i).getAQ2()+"-"+empFileList.get(i).getAQ3()+"-"+empFileList.get(i).getAQ4()));
        }
        mAdapter = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvGate.setAdapter(mAdapter);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        mAdapter.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etRelGate.setText(tit.split(",")[1]);
                etRelGate.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                mAdapter.SearchCity("");
                trListGate.setVisibility(View.GONE);
            }

            @Override
            public void OnClicktv(String tit, String tv) {

            }
        });

        for (int i = 0;i<empFileList.size();i++){
            teamList.add(change1(empFileList.get(i).getID()+","+empFileList.get(i).getAQ1()+"-"+empFileList.get(i).getAQ2()+"-"+empFileList.get(i).getAQ3()+"-"+empFileList.get(i).getAQ4()));
        }

        mAdapter2 = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvGate2.setAdapter(mAdapter2);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        mAdapter2.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etRelGate2.setText(tit.split(",")[1]);
                etRelGate2.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                mAdapter2.SearchCity("");
                trListGate2.setVisibility(View.GONE);
            }

            @Override
            public void OnClicktv(String tit, String tv) {

            }
        });

        inMAdaptr = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvInGate.setAdapter(inMAdaptr);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        inMAdaptr.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etInlGate.setText(tit.split(",")[1]);
                etInlGate.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                inMAdaptr.SearchCity("");
                trListInGate.setVisibility(View.GONE);
            }

            @Override
            public void OnClicktv(String tit, String tv) {

            }
        });
        inMAdaptr2 = new EmpListAdapter(GoodsIntelligenceActivity.this,teamList);
        lvInGate2.setAdapter(inMAdaptr2);

        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        inMAdaptr2.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
                etInlGate2.setText(tit.split(",")[1]);
                etInlGate2.setTag(tit.split(",")[0]);
//                paramMap.put("mengang", empFileList.get(position).getID());
                inMAdaptr2.SearchCity("");
                trListInGate2.setVisibility(View.GONE);
            }

            @Override
            public void OnClicktv(String tit, String tv) {

            }
        });
    }

    //简体转成繁体
    public String change(String changeText) {
        try {
            JChineseConvertor jChineseConvertor = JChineseConvertor.getInstance();
            changeText = jChineseConvertor.s2t(changeText);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return changeText;
    }
    //繁体转成简体
    public String change1(String changeText) {
        try {
            JChineseConvertor jChineseConvertor = JChineseConvertor
                    .getInstance();
            changeText = jChineseConvertor.t2s(changeText);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return changeText;
    }


    private void aboutAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==MESSAGE_TOAST){
                            finish();
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    private void worningAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==MESSAGE_TOAST){
                            finish();
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}


